/**
 * Created by xiangyufang on 2016/11/10.
 */
;(function ($, window, document, undefined) {
    /*** 管道名称 start ***/
    // 管道
    var $pipeline = $('#JQ_pipeline').select3();

    var $traffic_pipeline = $('#JQ_traffic_pipeline').select3({
        data: $pipeline.val('store'),
        title: '管道'
    });

    var $specific_pipeline = $('#JQ_specific_pipeline').select3({
        data: $pipeline.val('store'),
        title: '管道'
    });

    var $sewage_pipeline = $('#JQ_sewage_pipeline').select3({
        data: $pipeline.val('store'),
        title: '管道'
    });

    var $geologic_pipeline = $('#JQ_geologic_pipeline').select3({
        data: $pipeline.val('store'),
        title: '管道'
    });

    var $hard_pipeline = $('#JQ_hard_pipeline').select3({
        data: $pipeline.val('store'),
        title: '管道'
    });

    var $occupy_pipeline = $('#JQ_occupy_pipeline').select3({
        data: $pipeline.val('store'),
        title: '管道'
    });
    /*** 管道名称 end ***/

    /*** 全局变量 start ***/
    //获取当前日期
    function currentData(){
        var newData = new Date();
        var yearVal = newData.getFullYear();
        var moVal = newData.getMonth();
        var monVal = parseInt(moVal) + 1;
        var dateVal = newData.getDate();
        var mVal='',dVal='',curData;
        if(monVal<10){
            mVal = '0' + monVal;
        }else if(monVal>=10){
            mVal = monVal;
        }
        if(dateVal<10){
            dVal = '0' + dateVal;
        }else{
            dVal = dateVal;
        }
        curData = yearVal + '-' + mVal + '-' + dVal;

        return curData;
    }

    var curData = currentData();


    //页面跳转带过来的全局参数
    var $ambientId = $("#JQ_ambientId").val();
    var $ambientType = $("#JQ_ambientType").val();

    //表单DIV
    var $thirdForm = $("#JQ_third_form"); //第三方管道设施
    var $trafficForm = $("#JQ_traffic_form"); //交通设施
    var $specificForm = $("#JQ_specific_form"); //特定场所
    var $sewageForm = $("#JQ_sewage_form"); //地下排污排水装置
    var $geologicForm = $("#JQ_geologic_form"); //地址灾害
    var $resourceForm = $("#JQ_resource_form"); //应急资源
    var $hardForm = $("#JQ_hard_form");  //难以维修接近
    var $occupyForm = $("#JQ_occupy_form");  //管道占压

    //通用的表单输入框
    var $recorder = $("#JQ_recorder"); //记录人
    var $recordTime = $("#JQ_recordTime"); //记录时间
    var $remark = $("#JQ_remark"); //备注
    /*** 全局变量 end ***/

    // 上传图片
    var upcount = 0;    // 已上传图片数
    $('button.xyf-noninternal-upload-button').each(function(){
        var $this_button = $(this);
        var param = $this_button.attr('data-type');
        var dom_btn = $this_button.get(0);

        // 实例化一个plupload上传对象
        var uploader = new plupload.Uploader({
            browse_button: dom_btn,
            url: DyyBase.url_upload_file(),
            filters: {
                mime_types: [
                    {title:'Image files', extensions: 'jpg,jpeg,gif,png'}
                ]
            },
            multipart_params: {
                type: param
            },
            flash_swf_url: DyyBase.root_path+'/static/js/plugin/plupload/Moxie.swf',
            silverlight_xap_url: DyyBase.root_path+'/static/js/plugin/plupload/Moxie.xap',
            init: {
                BeforeUpload: function(u,f){},
                UploadProgress: function(u,f){},
                FileUploaded: function(u,f,info){
                    showUploadImg(info,$this_button);
                },
                UploadComplete: function(u,f){},
                Error: function(u,f){
                    if(f.code == -601){
                        var msg = f.file.name + '&nbsp;&nbsp;文件格式不正确!<p>请上传 (jpg,jpeg,gif,png) 格式图片!</p>';
                        $this_button.MSG({
                            type: 'error',
                            content: msg,
                            contentTitle: f.file.name,
                            contentAddon: '&nbsp;&nbsp;文件格式不正确!',
                            contentMust: '<p>请上传 (jpg,jpeg,gif,png) 格式图片</p>'
                        });
                    }
                },
                FilesAdded: function(u,f){
                    // 移除列队中的文件
                    function RF(u,f){
                        for(var j = 0, len = f.length; j < len; j++){
                            u.removeFile(f[j]);
                        }
                    }
                    if(f.length > 8){
                        RF(u,f);
                        $this_button.MSG({
                            type: 'error',
                            content: '上传图片数量不超过8张！'
                        });
                    }else{
                        upcount = upcount + f.length;
                        if(upcount > 6){
                            RF(u,f); upcount = upcount - f.length;
                            $this_button.MSG({
                                type: 'error',
                                content: '上传图片数量不超过6张！<br>您已上传 '+upcount+' 张'
                            });
                        }else{
                            uploader.start();
                        }
                    }
                }
            }
        });

        // 初始化
        uploader.init();
    });

    // 添加展示上传完成后的图片
    function showUploadImg(o,btn){
        var json = $.parseJSON(o.response);
        var path = DyyBase.file_path+json.result.path;
        var $span = $('<span class="zy-noninternal-span-img" data-path="'+path+'" data-id="'+json.result.id+'"><i data-id="'+json.result.id+'" title="删除照片">×</i><img src="'+path+'"></span>');
        var $label = $('label.zy-noninternal-upload-label');
        $label.append($span);
    }


    // 编辑加载图片
    function showEditImg(imgList){
        var $label = $('label.zy-noninternal-upload-label');
        for(var i=0;i<imgList.length;i++){
            var path = DyyBase.file_path+imgList[i].path;
            var $span = $('<span class="zy-noninternal-span-img" data-path="'+path+'" data-id="'+imgList[i].id+'"><i data-id="'+imgList[i].id+'" title="删除照片">×</i><img src="'+path+'"></span>');
            $label.append($span);
        }
        upcount = imgList.length;
    }

    // 为删除照片按钮添加代理事件
    $('label.zy-noninternal-upload-label').on('click','i',function(event){
        var $this_i = $(this);
        var attId = $this_i.attr('data-id');
        DyyBase.ajax(ambientApi.url_external_delete_img(),{attId:attId},function(dataset){
            if(dataset.bool){
                upcount = upcount - 1;
                $this_i.parent('span.zy-noninternal-span-img').remove();
            }
        });
        event.stopPropagation();
    });

    if($ambientType == 'AEPipeLine'){
        $thirdForm.show();
        loadThird();
    }else if($ambientType == 'TrafficFacilities'){
        $trafficForm.show();
        loadTraffic();
    }else if($ambientType == 'SpecificPlace'){
        $specificForm.show();
        loadSpecific();
    }else if($ambientType == 'Sewer'){
        $sewageForm.show();
        loadSewage();
    }else if($ambientType == 'GeologicHazard'){
        $geologicForm.show();
        loadGeologic();
    }else if($ambientType == 'EmergencyResource'){
        $resourceForm.show();
        loadResource();
    }else if($ambientType == 'DifficultyRepair'){
        $hardForm.show();
        loadHard();
    }else if($ambientType == 'PressObject'){
        $occupyForm.show();
        loadOccupy();
    }

    //第三方管道设施
    function loadThird(){
        //平行和交叉模块
        var $Across = $("#JQ_third_position_across");
        var $Parallel = $("#JQ_third_position_parallel");
        //选择框
        var $type=$('#JQ_third_type').select3({search:false});   // 类型
        DyyBase.ajax(ambientApi.url_common_form_type('AEPIPELINE_TYPE'), {}, function(dataset){
            var json = DyyBase.getSelect(dataset);
            $type.add(json);
        });
        var $method=$('#JQ_third_method').select3({search:false});   // 阴保方式
        DyyBase.ajax(ambientApi.url_common_form_type('CP_TYPE'), {}, function(dataset){
            var json = DyyBase.getSelect(dataset);
            $method.add(json);
        });
        var $position = $('#JQ_third_position').select3({
            search: false,
            data: [
                {id: 'CROSS', text: '交叉'},
                {id: 'PARALLEL', text: '平行'}
            ]
        });   // 相对位置关系
        $position.element.on('select',function(){
            checkThirdPosition($position,$Across,$Parallel);
        });
        var $acrossSafe = $("#JQ_third_across_safe").select3({
            search: false,
            data: [
                {id: 'YES', text: '是'},
                {id: 'NO', text: '否'}
            ]
        });  //交叉-是否为安全距离
        var $parallelSafe = $("#JQ_third_parallel_safe").select3({
            search: false,
            data: [
                {id: 'YES', text: '是'},
                {id: 'NO', text: '否'}
            ]
        });
        //输入框
        var $name = $("#JQ_third_name");  //名字
        var $company = $("#JQ_third_company");  //所属单位
        var $contact = $("#JQ_third_contact");  //联系人、单位
        var $tel = $("#JQ_third_tel");  //联系方式
        var $acrossX = $("#JQ_third_across_x");  //交叉-X
        var $acrossY = $("#JQ_third_across_y");  //交叉-Y
        var $acrossZ = $("#JQ_third_across_z");  //交叉-Z
        var $acrossSeat = $("#JQ_third_across_seat");  //交叉-位置描述
        var $acrossSpace = $("#JQ_third_across_space");  //交叉-垂直间距
        var $BeginX = $("#JQ_third_pBegin_x");  //平行-起点-X
        var $BeginY = $("#JQ_third_pBegin_y");  //平行-起点-Y
        var $BeginZ = $("#JQ_third_pBegin_z");  //平行-起点-Z
        var $BeginSeat = $("#JQ_third_pBegin_seat");  //平行-起点-位置描述
        var $EndX = $("#JQ_third_pEnd_x");  //平行-终点-X
        var $EndY = $("#JQ_third_pEnd_y");  //平行-终点-Y
        var $EndZ = $("#JQ_third_pEnd_z");  //平行-终点-Z
        var $EndSeat = $("#JQ_third_pEnd_seat");  //平行-终点-位置描述
        var $parallelSpace = $("#JQ_third_parallel_space");  //平行-垂直间距

        if($ambientId){
            DyyBase.ajax(ambientApi.url_ae_pipe_examine(), {id:$ambientId,type:'edit'}, function(dataSet){
                if(dataSet.bool){
                    var data = dataSet.result;
                    if(data){
                        $pipeline.fit(data.pipeLineId);
                        $type.fit(data.type);
                        $method.fit(data.cptype);
                        $position.fit(data.relativePositionRelation);
                        if(data.relativePositionRelation == "CROSS"){
                            $acrossSafe.fit(data.safeHeight);
                        }else if(data.relativePositionRelation == "PARALLEL"){
                            $parallelSafe.fit(data.safeHeight);
                        }
                        checkThirdPosition($position,$Across,$Parallel);
                        $name.val(data.name);
                        $company.val(data.owner);
                        $contact.val(data.contact);
                        $tel.val(data.telephone);
                        $acrossX.val(data.crossX);
                        $acrossY.val(data.crossY);
                        $acrossZ.val(data.crossZ);
                        $acrossSeat.val(data.locationDescription);
                        $acrossSpace.val(data.altitudeSeparation);
                        $BeginX.val(data.beginX);
                        $BeginY.val(data.beginY);
                        $BeginZ.val(data.beginZ);
                        $BeginSeat.val(data.beginDescription);
                        $EndX.val(data.endX);
                        $EndY.val(data.endY);
                        $EndZ.val(data.endZ);
                        $EndSeat.val(data.endDescription);
                        $parallelSpace.val(data.minDistance);

                        $recorder.val(data.recorder);
                        $recordTime.val(data.recordTime);
                        $remark.val(data.remarks);

                        if(data.imgList){
                            showEditImg(data.imgList);
                        }
                    }
                }
            });
        }

        var filter = {
            getSubmit: function () {
                var data = {};
                var posVal = $position.val();
                data.mode = true;
                //环境ID
                data.id = $ambientId;
                //管道名称参数
                data.pipeLineId = function () {
                    var v = $pipeline.val();
                    if(v){
                        return v;
                    }else{
                        $('#JQ_pipeline').TIP({content:'管道名称不能为空！'});
                        data.mode = false;
                    }
                }();
                //类型参数
                data.type = function () {
                    var v = $type.val();
                    if (v) {
                        return v;
                    }else{
                        $('#JQ_third_type').TIP({content:'类型不能为空！'});
                        data.mode = false;
                    }
                }();
                //阴保方式参数
                data.cptype = function () {
                    var v = $method.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //名称参数
                data.name = function () {
                    var v = $name.val();
                    if (v) {
                        return v;
                    }else{
                        $name.TIP({content:'名称不能为空！'});
                        data.mode = false;
                    }
                }();
                //所属单位参数
                data.owner = function () {
                    var v = $company.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //联系人、单位参数
                data.contact = function () {
                    var v = $contact.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //联系方式参数
                data.telephone = function () {
                    var v = $tel.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //相对位置关系
                data.relativePositionRelation = function () {
                    if (posVal) {
                        return posVal;
                    }else{
                        $('#JQ_third_position').TIP({content:'相对位置关系不能为空！'});
                        data.mode = false;
                    }
                }();
                if(posVal == 'PARALLEL'){
                    //平行-起点-X
                    data.beginX = function () {
                        var v = $BeginX.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginX.TIP({content:'起点X不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-起点-Y
                    data.beginY = function () {
                        var v = $BeginY.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginY.TIP({content:'起点Y不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-起点-Z
                    data.beginZ = function () {
                        var v = $BeginZ.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginZ.TIP({content:'起点Z不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-起点-位置描述
                    data.beginDescription = function () {
                        var v = $BeginSeat.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginSeat.TIP({content:'起点位置描述不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-X
                    data.endX = function () {
                        var v = $EndX.val();
                        if (v) {
                            return v;
                        }else{
                            $EndX.TIP({content:'终点X不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-Y
                    data.endY = function () {
                        var v = $EndY.val();
                        if (v) {
                            return v;
                        }else{
                            $EndY.TIP({content:'终点Y不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-Z
                    data.endZ = function () {
                        var v = $EndZ.val();
                        if (v) {
                            return v;
                        }else{
                            $EndZ.TIP({content:'终点Z不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-位置描述
                    data.endDescription = function () {
                        var v = $EndSeat.val();
                        if (v) {
                            return v;
                        }else{
                            $EndSeat.TIP({content:'终点位置描述不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行最小间距
                    data.minDistance = function () {
                        var v = $parallelSpace.val();
                        if (v) {
                            return v;
                        }
                        return "";
                    }();
                    //平行安全间距
                    data.safeHeight = function () {
                        var v = $parallelSafe.val();
                        if (v) {
                            return v;
                        }
                        return "";
                    }();

                    //交叉-X
                    data.crossX = function () {
                        return "";
                    }();
                    //交叉-Y
                    data.crossY = function () {
                        return "";
                    }();
                    //交叉-Z
                    data.crossZ = function () {
                        return "";
                    }();
                    //交叉-位置描述
                    data.locationDescription = function () {
                        return "";
                    }();
                    //交叉最小间距
                    data.altitudeSeparation = function () {
                        return "";
                    }();
                }else if(posVal == 'CROSS'){
                    //平行-起点-X
                    data.beginX = function () {
                        return "";
                    }();
                    //平行-起点-Y
                    data.beginY = function () {
                        return "";
                    }();
                    //平行-起点-Z
                    data.beginZ = function () {
                        return "";
                    }();
                    //平行-起点-位置描述
                    data.beginDescription = function () {
                        return "";
                    }();
                    //平行-终点-X
                    data.endX = function () {
                        return "";
                    }();
                    //平行-终点-Y
                    data.endY = function () {
                        return "";
                    }();
                    //平行-终点-Z
                    data.endZ = function () {
                        return "";
                    }();
                    //平行-终点-位置描述
                    data.endDescription = function () {
                        return "";
                    }();
                    //平行最小间距
                    data.minDistance = function () {
                        return "";
                    }();

                    //交叉-X
                    data.crossX = function () {
                        var v = $acrossX.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossX.TIP({content:'X不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //交叉-Y
                    data.crossY = function () {
                        var v = $acrossY.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossY.TIP({content:'Y不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //交叉-Z
                    data.crossZ = function () {
                        var v = $acrossZ.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossZ.TIP({content:'Z不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //交叉-位置描述
                    data.locationDescription = function () {
                        var v = $acrossSeat.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossSeat.TIP({content:'位置描述不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //交叉最小间距
                    data.altitudeSeparation = function () {
                        var v = $acrossSpace.val();
                        if (v) {
                            return v;
                        }
                        return "";
                    }();
                    //交叉安全间距
                    data.safeHeight = function () {
                        var v = $acrossSafe.val();
                        if (v) {
                            return v;
                        }
                        return "";
                    }();
                }
                //记录人参数
                data.recorder = function () {
                    var v = $recorder.val();
                    if (v) {

                        return v;
                    }
                    return "";
                }();
                //记录时间参数
                data.recordTime = function () {
                    var v = $recordTime.val();
                    if (v) {
                        if(!(Dyy.checkDateLate(v,curData))){
                            $recordTime.TIP({content:'记录时间不能大于当前时间'});
                            data.mode = false;
                        }
                        return v;
                    }
                    return "";
                }();
                //备注参数
                data.remarks = function () {
                    var v = $remark.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                // 照片
                data.imgs = function(){
                    var $label = $('span.zy-noninternal-span-img');
                    var arr = [];
                    if($label.length > 0){
                        $label.each(function(){
                            var $this_label = $(this);
                            arr.push($this_label.attr('data-id'));
                        });
                    }
                    return arr;
                }();
                return data;
            }
        };

        //保存
        $("#JQ_save").click(function(){
            var $form = $('#JQ_third_create_form');
            var bool = $form.verify();
            var param = filter.getSubmit();
            if(param.mode){
                if(bool){
                    DyyBase.ajax(ambientApi.url_ae_pipe_save(), DyyBase.convertToArr(param), function(dataSet){
                        if(dataSet.bool){
                            if(dataSet.result >= 1){
                                $(this).MSG({
                                    type: 'success',
                                    height: 300,
                                    content: '保存成功',
                                    yesBtnTxt: '确认',
                                    yesBtnAct: function(){
                                        window.location.href = ambientApi.url_ae_pipe_success();
                                    }
                                });
                            }
                        }
                    });
                }
            }
        })
    }

    //交通设施
    function loadTraffic(){
        //平行和交叉模块
        var $Across = $("#JQ_traffic_position_across");
        var $Parallel = $("#JQ_traffic_position_parallel");
        //选择框
        var $type=$('#JQ_traffic_type').select3({search:false});   // 类型
        DyyBase.ajax(ambientApi.url_common_form_type('AETRAFFIC_TYPE'), {}, function(dataset){
            var json = DyyBase.getSelect(dataset);
            $type.add(json);
        });
        var $position = $('#JQ_traffic_position').select3({
            search: false,
            data: [
                {id: 'CROSS', text: '交叉'},
                {id: 'PARALLEL', text: '平行'}
            ]
        });   // 相对位置关系
        $position.element.on('select',function(){
            checkThirdPosition($position,$Across,$Parallel);
        });
        var $acrossSafe = $("#JQ_traffic_across_safe").select3({
            search: false,
            data: [
                {id: 'YES', text: '是'},
                {id: 'NO', text: '否'}
            ]
        });  //交叉-是否为安全距离
        var $parallelSafe = $("#JQ_traffic_parallel_safe").select3({
            search: false,
            data: [
                {id: 'YES', text: '是'},
                {id: 'NO', text: '否'}
            ]
        });
        //输入框
        var $name = $("#JQ_traffic_name");  //名字
        var $company = $("#JQ_traffic_company");  //所属单位
        var $contact = $("#JQ_traffic_contact");  //联系人、单位
        var $tel = $("#JQ_traffic_tel");  //联系方式
        var $acrossX = $("#JQ_traffic_across_x");  //交叉-X
        var $acrossY = $("#JQ_traffic_across_y");  //交叉-Y
        var $acrossZ = $("#JQ_traffic_across_z");  //交叉-Z
        var $acrossSeat = $("#JQ_traffic_across_seat");  //交叉-位置描述
        var $acrossSpace = $("#JQ_traffic_across_space");  //交叉-垂直间距
        var $BeginX = $("#JQ_traffic_pBegin_x");  //平行-起点-X
        var $BeginY = $("#JQ_traffic_pBegin_y");  //平行-起点-Y
        var $BeginZ = $("#JQ_traffic_pBegin_z");  //平行-起点-Z
        var $BeginSeat = $("#JQ_traffic_pBegin_seat");  //平行-起点-位置描述
        var $EndX = $("#JQ_traffic_pEnd_x");  //平行-终点-X
        var $EndY = $("#JQ_traffic_pEnd_y");  //平行-终点-Y
        var $EndZ = $("#JQ_traffic_pEnd_z");  //平行-终点-Z
        var $EndSeat = $("#JQ_traffic_pEnd_seat");  //平行-终点-位置描述
        var $parallelLong = $("#JQ_traffic_parallel_long"); //平行-长度
        var $parallelSpace = $("#JQ_traffic_parallel_space");  //平行-垂直间距

        if($ambientId){
            DyyBase.ajax(ambientApi.url_ae_traffic_examine(), {id:$ambientId,type:'edit'}, function(dataSet){
                if(dataSet.bool){
                    var data = dataSet.result;
                    if(data){
                        $traffic_pipeline.fit(data.pipeLineId);
                        $type.fit(data.type);
                        $position.fit(data.relativePositionRelation);
                        if(data.relativePositionRelation == "CROSS"){
                            $acrossSafe.fit(data.safeHeight);
                        }else if(data.relativePositionRelation == "PARALLEL"){
                            $parallelSafe.fit(data.safeHeight);
                        }
                        checkThirdPosition($position,$Across,$Parallel);


                        $name.val(data.name);
                        $company.val(data.owner);
                        $contact.val(data.contact);
                        $tel.val(data.telephone);
                        $acrossX.val(data.crossX);
                        $acrossY.val(data.crossY);
                        $acrossZ.val(data.crossZ);
                        $acrossSeat.val(data.locationDescription);
                        $acrossSpace.val(data.altitudeSeparation);
                        $BeginX.val(data.beginX);
                        $BeginY.val(data.beginY);
                        $BeginZ.val(data.beginZ);
                        $BeginSeat.val(data.beginDescription);
                        $EndX.val(data.endX);
                        $EndY.val(data.endY);
                        $EndZ.val(data.endZ);
                        $EndSeat.val(data.endDescription);
                        $parallelSpace.val(data.minDistance);

                        $recorder.val(data.recorder);
                        $recordTime.val(data.recordTime);
                        $remark.val(data.remarks);

                        if(data.imgList){
                            showEditImg(data.imgList);
                        }
                    }
                }
            });
        }

        var filter = {
            getSubmit: function () {
                var data = {};
                var posVal = $position.val();
                data.mode = true;
                //环境ID
                data.id = $ambientId;
                //管道名称参数
                data.pipeLineId = function () {
                    var v = $traffic_pipeline.val();
                    if(v){
                        return v;
                    }else{
                        $('#JQ_traffic_pipeline').TIP({content:'管道名称不能为空！'});
                        data.mode = false;
                    }
                }();
                //类型参数
                data.type = function () {
                    var v = $type.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //名称参数
                data.name = function () {
                    var v = $name.val();
                    if (v) {
                        return v;
                    }else{
                        $name.TIP({content:'名称不能为空！'});
                        data.mode = false;
                    }
                }();
                //所属单位参数
                data.owner = function () {
                    var v = $company.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //联系人、单位参数
                data.contact = function () {
                    var v = $contact.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //联系方式参数
                data.telephone = function () {
                    var v = $tel.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //相对位置关系
                data.relativePositionRelation = function () {
                    if (posVal) {
                        return posVal;
                    }else{
                        $('#JQ_traffic_position').TIP({content:'相对位置关系不能为空！'});
                        data.mode = false;
                    }
                }();
                if(posVal == 'PARALLEL'){
                    //平行-起点-X
                    data.beginX = function () {
                        var v = $BeginX.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginX.TIP({content:'起点X不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-起点-Y
                    data.beginY = function () {
                        var v = $BeginY.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginY.TIP({content:'起点Y不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-起点-Z
                    data.beginZ = function () {
                        var v = $BeginZ.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginZ.TIP({content:'起点Z不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-起点-位置描述
                    data.beginDescription = function () {
                        var v = $BeginSeat.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginSeat.TIP({content:'起点位置描述不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-X
                    data.endX = function () {
                        var v = $EndX.val();
                        if (v) {
                            return v;
                        }else{
                            $EndX.TIP({content:'终点X不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-Y
                    data.endY = function () {
                        var v = $EndY.val();
                        if (v) {
                            return v;
                        }else{
                            $EndY.TIP({content:'终点Y不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-Z
                    data.endZ = function () {
                        var v = $EndZ.val();
                        if (v) {
                            return v;
                        }else{
                            $EndZ.TIP({content:'终点Z不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-位置描述
                    data.endDescription = function () {
                        var v = $EndSeat.val();
                        if (v) {
                            return v;
                        }else{
                            $EndSeat.TIP({content:'终点位置描述不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行最小间距
                    data.minDistance = function () {
                        var v = $parallelSpace.val();
                        if (v) {
                            return v;
                        }
                        return "";
                    }();
                    //平行长度
                    data.parallelLength = function () {
                        var v = $parallelLong.val();
                        if (v) {
                            return v;
                        }
                        return "";
                    }();
                    //平行安全间距
                    data.safeHeight = function () {
                        var v = $parallelSafe.val();
                        if (v) {
                            return v;
                        }
                        return "";
                    }();

                    //交叉-X
                    data.crossX = function () {
                        return "";
                    }();
                    //交叉-Y
                    data.crossY = function () {
                        return "";
                    }();
                    //交叉-Z
                    data.crossZ = function () {
                        return "";
                    }();
                    //交叉-位置描述
                    data.locationDescription = function () {
                        return "";
                    }();
                    //交叉最小间距
                    data.altitudeSeparation = function () {
                        return "";
                    }();
                }else if(posVal == 'CROSS'){
                    //平行-起点-X
                    data.beginX = function () {
                        return "";
                    }();
                    //平行-起点-Y
                    data.beginY = function () {
                        return "";
                    }();
                    //平行-起点-Z
                    data.beginZ = function () {
                        return "";
                    }();
                    //平行-起点-位置描述
                    data.beginDescription = function () {
                        return "";
                    }();
                    //平行-终点-X
                    data.endX = function () {
                        return "";
                    }();
                    //平行-终点-Y
                    data.endY = function () {
                        return "";
                    }();
                    //平行-终点-Z
                    data.endZ = function () {
                        return "";
                    }();
                    //平行-终点-位置描述
                    data.endDescription = function () {
                        return "";
                    }();
                    //平行最小间距
                    data.minDistance = function () {
                        return "";
                    }();
                    //平行长度
                    data.parallelLength = function () {
                        return "";
                    }();

                    //交叉-X
                    data.crossX = function () {
                        var v = $acrossX.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossX.TIP({content:'X不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //交叉-Y
                    data.crossY = function () {
                        var v = $acrossY.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossY.TIP({content:'Y不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //交叉-Z
                    data.crossZ = function () {
                        var v = $acrossZ.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossZ.TIP({content:'Z不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //交叉-位置描述
                    data.locationDescription = function () {
                        var v = $acrossSeat.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossSeat.TIP({content:'位置描述不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //交叉最小间距
                    data.altitudeSeparation = function () {
                        var v = $acrossSpace.val();
                        if (v) {
                            return v;
                        }
                        return "";
                    }();
                    //交叉安全间距
                    data.safeHeight = function () {
                        var v = $acrossSafe.val();
                        if (v) {
                            return v;
                        }
                        return "";
                    }();
                }
                //记录人参数
                data.recorder = function () {
                    var v = $recorder.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //记录时间参数
                data.recordTime = function () {
                    var v = $recordTime.val();
                    if (v) {
                        if(!(Dyy.checkDateLate(v,curData))){
                            $recordTime.TIP({content:'记录时间不能大于当前时间'});
                            data.mode = false;
                        }
                        return v;
                    }
                    return "";
                }();
                //备注参数
                data.remarks = function () {
                    var v = $remark.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                // 照片
                data.imgs = function(){
                    var $label = $('span.zy-noninternal-span-img');
                    var arr = [];
                    if($label.length > 0){
                        $label.each(function(){
                            var $this_label = $(this);
                            arr.push($this_label.attr('data-id'));
                        });
                    }
                    return arr;
                }();
                return data;
            }
        };

        //保存
        $("#JQ_save").click(function(){
            var $form = $('#JQ_traffic_create_form');
            var bool = $form.verify();
            var param = filter.getSubmit();
            if(param.mode){
                if(bool){
                    DyyBase.ajax(ambientApi.url_ae_traffic_save(), DyyBase.convertToArr(param), function(dataSet){
                        if(dataSet.bool){
                            $(this).MSG({
                                type: 'success',
                                height: 300,
                                content: '保存成功',
                                yesBtnTxt: '确认',
                                yesBtnAct: function(){
                                    window.location.href = ambientApi.url_ae_traffic_success();
                                }
                            });
                        }
                    });
                }
            }

        })
    }

    //特定场所
    function loadSpecific(){
        //选择框
        var $type=$('#JQ_specific_type').select3({search:false});   // 类型
        DyyBase.ajax(ambientApi.url_common_form_type('SPECIFIC_PLACE_TYPE'), {}, function(dataset){
            var json = DyyBase.getSelect(dataset);
            $type.add(json);
        });
        var $genre = $('#JQ_specific_genre').select3({search:false});   // 类别
        DyyBase.ajax(ambientApi.url_common_form_type('SPECIFIC_PLACE_CATEGORY'), {}, function(dataset){
            var json = DyyBase.getSelect(dataset);
            $genre.add(json);
        });
        //输入框
        var $name = $("#JQ_specific_name");  //名字
        var $company = $("#JQ_specific_company");  //人口数量
        var $X = $("#JQ_specific_x");  //X
        var $Y = $("#JQ_specific_y");  //Y
        var $Z = $("#JQ_specific_z");  //Z
        var $Seat = $("#JQ_specific_seat");  //位置描述
        var $Space = $("#JQ_specific_space");  //与管道最小间距

        if($ambientId){
            DyyBase.ajax(ambientApi.url_ae_specific_examine(), {id:$ambientId,type:'edit'}, function(dataSet){
                if(dataSet.bool){
                    var data = dataSet.result;
                    if(data){
                        $specific_pipeline.fit(data.pipeLineId);
                        $type.fit(data.type);
                        $genre.fit(data.category);


                        $name.val(data.name);
                        $company.val(data.population);
                        $X.val(data.positionX);
                        $Y.val(data.positionY);
                        $Z.val(data.positionZ);
                        $Seat.val(data.locationDescription);
                        $Space.val(data.minDistance);

                        $recorder.val(data.recorder);
                        $recordTime.val(data.recordTime);
                        $remark.val(data.remarks);

                        if(data.imgList){
                            showEditImg(data.imgList);
                        }
                    }
                }
            });
        }

        var filter = {
            getSubmit: function () {
                var data = {};
                data.mode = true;
                //环境ID
                data.id = $ambientId;
                //管道名称参数
                data.pipeLineId = function () {
                    var v = $specific_pipeline.val();
                    if(v){
                        return v;
                    }else{
                        $('#JQ_specific_pipeline').TIP({content:'管道名称不能为空！'});
                        data.mode = false;
                    }
                }();
                //类型参数
                data.type = function () {
                    var v = $type.val();
                    if (v) {
                        return v;
                    }else{
                        $('#JQ_specific_type').TIP({content:'类型不能为空！'});
                        data.mode = false;
                    }
                }();
                //名称参数
                data.name = function () {
                    var v = $name.val();
                    if (v) {
                        return v;
                    }else{
                        $name.TIP({content:'名称不能为空！'});
                        data.mode = false;
                    }
                }();
                //所属单位参数
                data.population = function () {
                    var v = $company.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //特定场所类别参数
                data.category = function () {
                    var v = $genre.val();
                    if (v) {
                        return v;
                    }else{
                        $('#JQ_specific_genre').TIP({content:'特定场所类别不能为空！'});
                        data.mode = false;
                    }
                }();
                //X
                data.positionX = function () {
                    var v = $X.val();
                    if (v) {
                        return v;
                    }else{
                        $X.TIP({content:'X不能为空！'});
                        data.mode = false;
                    }
                }();
                //Y
                data.positionY = function () {
                    var v = $Y.val();
                    if (v) {
                        return v;
                    }else{
                        $Y.TIP({content:'Y不能为空！'});
                        data.mode = false;
                    }
                }();
                //Z
                data.positionZ = function () {
                    var v = $Z.val();
                    if (v) {
                        return v;
                    }else{
                        $Z.TIP({content:'Z不能为空！'});
                        data.mode = false;
                    }
                }();
                //位置描述
                data.locationDescription = function () {
                    var v = $Seat.val();
                    if (v) {
                        return v;
                    }else{
                        $Seat.TIP({content:'位置描述不能为空！'});
                        data.mode = false;
                    }
                }();
                //与管道最小间距
                data.minDistance = function () {
                    var v = $Space.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //记录人参数
                data.recorder = function () {
                    var v = $recorder.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //记录时间参数
                data.recordTime = function () {
                    var v = $recordTime.val();
                    if (v) {
                        if(!(Dyy.checkDateLate(v,curData))){
                            $recordTime.TIP({content:'记录时间不能大于当前时间'});
                            data.mode = false;
                        }
                        return v;
                    }
                    return "";
                }();
                //备注参数
                data.remarks = function () {
                    var v = $remark.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                // 照片
                data.imgs = function(){
                    var $label = $('span.zy-noninternal-span-img');
                    var arr = [];
                    if($label.length > 0){
                        $label.each(function(){
                            var $this_label = $(this);
                            arr.push($this_label.attr('data-id'));
                        });
                    }
                    return arr;
                }();
                return data;
            }
        };

        //保存
        $("#JQ_save").click(function(){
            var $form = $('#JQ_specific_create_form');
            var bool = $form.verify();
            var param = filter.getSubmit();
            if(param.mode){
                if(bool){
                    DyyBase.ajax(ambientApi.url_ae_specific_save(), DyyBase.convertToArr(param), function(dataSet){
                        if(dataSet.bool){
                            if(dataSet.result >= 1){
                                $(this).MSG({
                                    type: 'success',
                                    height: 300,
                                    content: '保存成功',
                                    yesBtnTxt: '确认',
                                    yesBtnAct: function(){
                                        window.location.href = ambientApi.url_ae_specific_success();
                                    }
                                });
                            }
                        }
                    });
                }
            }

        })
    }

    //地下排污排水设施
    function loadSewage(){
        //平行和交叉模块
        var $Across = $("#JQ_sewage_position_across");
        var $Parallel = $("#JQ_sewage_position_parallel");
        //选择框
        var $type=$('#JQ_sewage_type').select3({search:false});   // 类型
        DyyBase.ajax(ambientApi.url_common_form_type('SEWER_TYPE'), {}, function(dataset){
            var json = DyyBase.getSelect(dataset);
            $type.add(json);
        });
        var $position = $('#JQ_sewage_position').select3({
            search: false,
            data: [
                {id: 'CROSS', text: '交叉'},
                {id: 'PARALLEL', text: '平行'}
            ]
        });   // 相对位置关系
        $position.element.on('select',function(){
            checkThirdPosition($position,$Across,$Parallel);
        });
        var $parallelSafe = $("#JQ_sewage_parallel_safe").select3({
            search: false,
            data: [
                {id: 'YES', text: '是'},
                {id: 'NO', text: '否'}
            ]
        });
        var $acrossSafe = $("#JQ_sewage_across_safe").select3({
            search: false,
            data: [
                {id: 'YES', text: '是'},
                {id: 'NO', text: '否'}
            ]
        });//是否密闭空间

        //输入框
        var $name = $("#JQ_sewage_name");  //名字
        var $company = $("#JQ_sewage_company");  //所属单位
        var $tel = $("#JQ_sewage_tel");  //联系方式

        var $acrossName = $("#JQ_sewage_across_name");  //交叉-桩号
        var $acrossSpace = $("#JQ_sewage_across_space");  //交叉-相对桩的距离
        var $acrossX = $("#JQ_sewage_across_x");  //交叉-X
        var $acrossY = $("#JQ_sewage_across_y");  //交叉-Y
        var $acrossZ = $("#JQ_sewage_across_z");  //交叉-Z
        var $acrossSeat = $("#JQ_sewage_across_seat");  //交叉-位置描述

        var $BeginName = $("#JQ_sewage_pBegin_number");  //平行-起点-桩号
        var $BeginSpace = $("#JQ_sewage_pBegin_space");  //平行-起点-相对桩的距离
        var $BeginX = $("#JQ_sewage_pBegin_x");  //平行-起点-X
        var $BeginY = $("#JQ_sewage_pBegin_y");  //平行-起点-Y
        var $BeginZ = $("#JQ_sewage_pBegin_z");  //平行-起点-Z

        var $EndName = $("#JQ_sewage_pEnd_number");  //平行-终点-桩号
        var $EndSpace = $("#JQ_sewage_pEnd_space");  //平行-终点-相对桩的距离
        var $EndX = $("#JQ_sewage_pEnd_x");  //平行-终点-X
        var $EndY = $("#JQ_sewage_pEnd_y");  //平行-终点-Y
        var $EndZ = $("#JQ_sewage_pEnd_z");  //平行-终点-Z

        var $parallelSeat = $("#JQ_sewage_parallel_seat");  //平行-终点-位置描述
        var $parallelSpace = $("#JQ_sewage_parallel_space");  //平行-垂直间距


        if($ambientId){
            DyyBase.ajax(ambientApi.url_ae_sewer_examine(), {id:$ambientId,type:'edit'}, function(dataSet){
                if(dataSet.bool){
                    var data = dataSet.result;
                    if(data){
                        $sewage_pipeline.fit(data.pipeLineId);
                        $type.fit(data.type);
                        $position.fit(data.relativePositionRelation);
                        checkThirdPosition($position,$Across,$Parallel);
                        if(data.relativePositionRelation == 'CROSS'){
                            $acrossSeat.val(data.locationDescription);
                            $acrossSafe.fit(data.confinedSpace);
                        }else if(data.relativePositionRelation == 'PARALLEL'){
                            $parallelSafe.fit(data.confinedSpace);
                            $parallelSeat.val(data.locationDescription);
                        }

                        $name.val(data.name);
                        $company.val(data.owner);
                        $tel.val(data.telephone);

                        $acrossName.val(data.crossNagmInput);
                        $acrossSpace.val(data.crossNagmMileageInput);
                        $acrossX.val(data.crossX);
                        $acrossY.val(data.crossY);
                        $acrossZ.val(data.crossZ);

                        $BeginName.val(data.beginNagmInput);
                        $BeginSpace.val(data.beginNagmMileageInput);
                        $BeginX.val(data.beginX);
                        $BeginY.val(data.beginY);
                        $BeginZ.val(data.beginZ);

                        $EndName.val(data.endNagmInput);
                        $EndSpace.val(data.endNagmMileageInput);
                        $EndX.val(data.endX);
                        $EndY.val(data.endY);
                        $EndZ.val(data.endZ);

                        $parallelSpace.val(data.minDistance);

                        $recorder.val(data.recorder);
                        $recordTime.val(data.recordTime);
                        $remark.val(data.remarks);

                        if(data.imgList){
                            showEditImg(data.imgList);
                        }
                    }
                }
            });
        }

        var filter = {
            getSubmit: function () {
                var data = {};
                var posVal = $position.val();
                data.mode = true;
                //环境ID
                data.id = $ambientId;
                //管道名称参数
                data.pipeLineId = function () {
                    var v = $sewage_pipeline.val();
                    if(v){
                        return v;
                    }else{
                        $('#JQ_sewage_pipeline').TIP({content:'管道名称不能为空！'});
                        data.mode = false;
                    }
                }();
                //类型参数
                data.type = function () {
                    var v = $type.val();
                    if (v) {
                        return v;
                    }else{
                        $('#JQ_sewage_type').TIP({content:'类型不能为空！'});
                        data.mode = false;
                    }
                }();
                //名称参数
                data.name = function () {
                    var v = $name.val();
                    if (v) {
                        return v;
                    }else{
                        $name.TIP({content:'名称不能为空！'});
                        data.mode = false;
                    }
                }();
                //所属单位参数
                data.owner = function () {
                    var v = $company.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //联系方式参数
                data.telephone = function () {
                    var v = $tel.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //相对位置关系
                data.relativePositionRelation = function () {
                    if (posVal) {
                        return posVal;
                    }else{
                        $('#JQ_sewage_position').TIP({content:'相对位置关系不能为空！'});
                        data.mode = false;
                    }
                }();
                if(posVal == 'PARALLEL'){
                    //平行-起点-桩号
                    data.beginNagmInput = function () {
                        var v = $BeginName.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginName.TIP({content:'桩号不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-起点-相对桩的距离
                    data.beginNagmMileageInput = function () {
                        var v = $BeginSpace.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginSpace.TIP({content:'相对桩的距离不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-起点-X
                    data.beginX = function () {
                        var v = $BeginX.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginX.TIP({content:'X不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-起点-Y
                    data.beginY = function () {
                        var v = $BeginY.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginY.TIP({content:'Y不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-起点-Z
                    data.beginZ = function () {
                        var v = $BeginZ.val();
                        if (v) {
                            return v;
                        }else{
                            $BeginZ.TIP({content:'Z不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-桩号
                    data.endNagmInput = function () {
                        var v = $EndName.val();
                        if (v) {
                            return v;
                        }else{
                            $EndName.TIP({content:'桩号不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-相对桩的距离
                    data.endNagmMileageInput = function () {
                        var v = $EndSpace.val();
                        if (v) {
                            return v;
                        }else{
                            $EndSpace.TIP({content:'相对桩的距离不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-X
                    data.endX = function () {
                        var v = $EndX.val();
                        if (v) {
                            return v;
                        }else{
                            $EndX.TIP({content:'X不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-Y
                    data.endY = function () {
                        var v = $EndY.val();
                        if (v) {
                            return v;
                        }else{
                            $EndY.TIP({content:'Y不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行-终点-Z
                    data.endZ = function () {
                        var v = $EndZ.val();
                        if (v) {
                            return v;
                        }else{
                            $EndZ.TIP({content:'Z不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //位置描述
                    data.locationDescription = function () {
                        var v = $parallelSeat.val();
                        if (v) {
                            return v;
                        }else{
                            $parallelSeat.TIP({content:'位置描述不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行最小间距
                    data.minDistance = function () {
                        var v = $parallelSpace.val();
                        if (v) {
                            return v;
                        }else{
                            $parallelSpace.TIP({content:'平行最小间距不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行是否密闭空间
                    data.confinedSpace = function () {
                        var v = $parallelSafe.val();
                        if (v) {
                            return v;
                        }else{
                            $("#JQ_sewage_parallel_safe").TIP({content:'密闭空间不能为空！'});
                            data.mode = false;
                        }
                    }();

                    //交叉-桩号
                    data.crossNagmInput = function () {
                        return "";
                    }();
                    //交叉-相对桩的距离
                    data.crossNagmMileageInput = function () {
                        return "";
                    }();
                    //交叉-X
                    data.crossX = function () {
                        return "";
                    }();
                    //交叉-Y
                    data.crossY = function () {
                        return "";
                    }();
                    //交叉-Z
                    data.crossZ = function () {
                        return "";
                    }();

                }else if(posVal == 'CROSS'){
                    //平行-起点-桩号
                    data.beginNagmInput = function () {
                        return "";
                    }();
                    //平行-起点-相对桩的距离
                    data.beginNagmMileageInput = function () {
                        return "";
                    }();
                    //平行-起点-X
                    data.beginX = function () {
                        return "";
                    }();
                    //平行-起点-Y
                    data.beginY = function () {
                        return "";
                    }();
                    //平行-起点-Z
                    data.beginZ = function () {
                        return "";
                    }();
                    //平行-终点-桩号
                    data.endNagmInput = function () {
                        return "";
                    }();
                    //平行-终点-相对桩的距离
                    data.endNagmMileageInput = function () {
                        return "";
                    }();
                    //平行-终点-X
                    data.endX = function () {
                        return "";
                    }();
                    //平行-终点-Y
                    data.endY = function () {
                        return "";
                    }();
                    //平行-终点-Z
                    data.endZ = function () {
                        return "";
                    }();
                    //位置描述
                    data.locationDescription = function () {
                        var v = $acrossSeat.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossSeat.TIP({content:'位置描述不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //平行最小间距
                    data.minDistance = function () {
                        return "";
                    }();
                    //是否密闭空间
                    data.confinedSpace = function () {
                        var v = $acrossSafe.val();
                        if (v) {
                            return v;
                        }else{
                            $("#JQ_sewage_across_safe").TIP({content:'密闭空间不能为空！'});
                            data.mode = false;
                        }
                    }();

                    //交叉-桩号
                    data.crossNagmInput = function () {
                        var v = $acrossName.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossName.TIP({content:'桩号不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //交叉-相对桩的距离
                    data.crossNagmMileageInput = function () {
                        var v = $acrossSpace.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossSpace.TIP({content:'相对桩的距离不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //交叉-X
                    data.crossX = function () {
                        var v = $acrossX.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossX.TIP({content:'X不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //交叉-Y
                    data.crossY = function () {
                        var v = $acrossY.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossY.TIP({content:'Y不能为空！'});
                            data.mode = false;
                        }
                    }();
                    //交叉-Z
                    data.crossZ = function () {
                        var v = $acrossZ.val();
                        if (v) {
                            return v;
                        }else{
                            $acrossZ.TIP({content:'Z不能为空！'});
                            data.mode = false;
                        }
                    }();
                }
                //记录人参数
                data.recorder = function () {
                    var v = $recorder.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //记录时间参数
                data.recordTime = function () {
                    var v = $recordTime.val();
                    if (v) {
                        if(!(Dyy.checkDateLate(v,curData))){
                            $recordTime.TIP({content:'记录时间不能大于当前时间'});
                            data.mode = false;
                        }
                        return v;
                    }
                    return "";
                }();
                //备注参数
                data.remarks = function () {
                    var v = $remark.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                // 照片
                data.imgs = function(){
                    var $label = $('span.zy-noninternal-span-img');
                    var arr = [];
                    if($label.length > 0){
                        $label.each(function(){
                            var $this_label = $(this);
                            arr.push($this_label.attr('data-id'));
                        });
                    }
                    return arr;
                }();
                return data;
            }
        };

        //保存
        $("#JQ_save").click(function(){
            var $form = $('#JQ_sewage_create_form');
            var bool = $form.verify();
            var param = filter.getSubmit();
            if(param.mode){
                if(bool){DyyBase.ajax(ambientApi.url_ae_sewer_save(), DyyBase.convertToArr(param), function(dataSet){
                    if(dataSet.bool){
                        if(dataSet.result >= 1){
                            $(this).MSG({
                                type: 'success',
                                height: 300,
                                content: '保存成功',
                                yesBtnTxt: '确认',
                                yesBtnAct: function(){
                                    window.location.href = ambientApi.url_ae_sewer_success();
                                }
                            });
                        }
                    }
                });}
            }

        })
    }

    //地址灾害
    function loadGeologic(){
        //选择框
        var $type = $("#JQ_geologic_type").select3({search:false});
        DyyBase.ajax(ambientApi.url_common_form_type('AE_GEOLOGIC_HAZARD_TYPE'), {}, function(dataset){
            var json = DyyBase.getSelect(dataset);
            $type.add(json);
        });
        var $risk = $('#JQ_geologic_risk').select3({
            search:false,
            data:[
                {id:'HIGH',text:'高'},
                {id:'MEDIUMANDHIGH',text:'中高'},
                {id:'MEDIUM',text:'中'},
                {id:'MIDDLEANDLOW',text:'中低'},
                {id:'LOW',text:'低'},
                {id:'UNKNOWN',text:'未知'}
            ]
        });


        var $val = $("#JQ_geologic_val");  //风险概率分值
        var $grade = $("#JQ_geologic_grade");  //风险概率分级

        var $beginNum = $("#JQ_geologic_beginNum");  //起点-桩号
        var $beginNear = $("#JQ_geologic_beginNear");  //起点-最近桩距离

        var $endNum = $("#JQ_geologic_endNum");  //终点-桩号
        var $endNear = $("#JQ_geologic_endNear");  //终点-最近桩距离

        var $position = $("#JQ_geologic_position");  //位置描述
        var $aftermath = $("#JQ_geologic_aftermath");  //后果分级

        if($ambientId){
            DyyBase.ajax(ambientApi.url_ae_geologic_examine(), {id:$ambientId,type:'edit'}, function(dataSet){
                if(dataSet.bool){
                    var data = dataSet.result;
                    if(data){
                        $geologic_pipeline.fit(data.pipeLineId);
                        $type.fit(data.type);

                        $val.val(data.riskProbabilityScore);
                        $grade.val(data.riskProbabilityLevel);
                        $beginNum.val(data.beginNagmInput);
                        $beginNear.val(data.beginNagmMileageInput);
                        $endNum.val(data.endNagmInput);
                        $endNear.val(data.endNagmMileageInput);
                        $position.val(data.locationDescription);
                        $aftermath.val(data.consequenceLevel);
                        $risk.fit(data.riskLevel);

                        $recorder.val(data.recorder);
                        $recordTime.val(data.recordTime);
                        $remark.val(data.remarks);

                        if(data.imgList){
                            showEditImg(data.imgList);
                        }
                    }
                }
            });
        }

        var filter = {
            getSubmit: function () {
                var data = {};
                data.mode = true;
                //环境ID
                data.id = $ambientId;
                //管道名称参数
                data.pipeLineId = function () {
                    var v = $geologic_pipeline.val();
                    if(v){
                        return v;
                    }
                    return "";
                }();
                //l类型
                data.type = function () {
                    var v = $type.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //风险等级分值
                data.riskProbabilityScore = function () {
                    var v = $val.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //风险等级分级
                data.riskProbabilityLevel = function () {
                    var v = $grade.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //起点-桩号
                data.beginNagmInput = function () {
                    var v = $beginNum.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //起点-最近桩距离
                data.beginNagmMileageInput = function () {
                    var v = $beginNear.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //终点-桩号
                data.endNagmInput = function () {
                    var v = $endNum.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //终点-最近桩距离
                data.endNagmMileageInput = function () {
                    var v = $endNear.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //位置描述
                data.locationDescription = function () {
                    var v = $position.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //后果分级
                data.consequenceLevel = function () {
                    var v = $aftermath.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //风险等级
                data.riskLevel = function () {
                    var v = $risk.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //记录人参数
                data.recorder = function () {
                    var v = $recorder.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //记录时间参数
                data.recordTime = function () {
                    var v = $recordTime.val();
                    if (v) {
                        if(!(Dyy.checkDateLate(v,curData))){
                            $recordTime.TIP({content:'记录时间不能大于当前时间'});
                            data.mode = false;
                        }
                        return v;
                    }
                    return "";
                }();
                //备注参数
                data.remarks = function () {
                    var v = $remark.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                // 照片
                data.imgs = function(){
                    var $label = $('span.zy-noninternal-span-img');
                    var arr = [];
                    if($label.length > 0){
                        $label.each(function(){
                            var $this_label = $(this);
                            arr.push($this_label.attr('data-id'));
                        });
                    }
                    return arr;
                }();
                return data;
            }
        };

        //保存
        $("#JQ_save").click(function(){
            var $form = $('#JQ_geologic_create_form');
            var bool = $form.verify();
            var param = filter.getSubmit();
            if(param.mode){
                if(bool){
                    DyyBase.ajax(ambientApi.url_ae_geologic_save(), DyyBase.convertToArr(param), function(dataSet){
                        if(dataSet.bool){
                            if(dataSet.result >= 1) {
                                $(this).MSG({
                                    type: 'success',
                                    height: 300,
                                    content: '保存成功',
                                    yesBtnTxt: '确认',
                                    yesBtnAct: function () {
                                        window.location.href = ambientApi.url_ae_geologic_success();
                                    }
                                });
                            }
                        }
                    });
                }
            }

        })
    }

    //应急资源
    function loadResource(){
        //选择框
        var $genre = $('#JQ_resource_genre').select3({search:false});   // 类别
        DyyBase.ajax(ambientApi.url_common_form_type('AE_EMERGENCY_RESOURCE_TYPE'), {}, function(dataset){
            var json = DyyBase.getSelect(dataset);
            $genre.add(json);
        });
        var $capital = $('#JQ_resource_capital').select3({
            search: false,
            data : DyyBase.getSelectData(100000, 0, false)
        });   // 省
        $capital.element.on('select',function(e,v){
            var id = v || $capital.val();
            if(id){
                $city.add(DyyBase.getSelectData(id, 1, false));
                $county.add('');
            }else{
                $city.add('');
                $county.add('');
            }
        });
        var $city = $('#JQ_resource_city').select3({
            search: false
        });   // 市
        $city.element.on('select',function(e,v){
            var id = v || $city.val();
            if(id){
                $county.add(DyyBase.getSelectData(id, 2, false));
            }else{
                $county.add('');
            }
        });
        var $county = $('#JQ_resource_county').select3({
            search: false
        });   // 县

        var $town = $('#JQ_resource_town');   //镇和乡
        var $village = $('#JQ_resource_village');   // 村
        //输入框
        var $name = $("#JQ_resource_name");  //名字
        var $contact = $("#JQ_resource_contact");  //联系人、单位
        var $tel = $("#JQ_resource_tel");  //联系方式

        if($ambientId){
            DyyBase.ajax(ambientApi.url_ae_emergency_examine(), {id:$ambientId,type:'edit'}, function(dataSet){
                if(dataSet.bool){
                    var data = dataSet.result;
                    if(data){
                        $genre.fit(data.type);

                        //省
                        var capitalData = DyyBase.getSelectData(100000, 0, false);
                        var capital_id ;
                        for(var h=0;h<capitalData.length;h++){
                            if(capitalData[h].text == data.province){
                                capital_id = capitalData[h].id;
                            }
                        }
                        $capital.fit(capital_id);


                        //市
                        var capital_val = $capital.val();
                        var cityData = DyyBase.getSelectData(capital_val, 1, false);
                        var city_id ;
                        for(var m=0;m<cityData.length;m++){
                            if(cityData[m].text == data.city){
                                city_id = cityData[m].id;
                            }
                        }
                        $city.add(cityData).fit(city_id);

                        //区
                        var city_val = $city.val();
                        var countyData = DyyBase.getSelectData(city_val, 2, false);
                        var county_id ;
                        for(var n=0;n<countyData.length;n++){
                            if(countyData[n].text == data.district){
                                county_id = countyData[n].id;
                            }
                        }
                        $county.add(countyData).fit(county_id);


                        $town.val(data.town);
                        $village.val(data.village);
                        $name.val(data.name);
                        $contact.val(data.contact);
                        $tel.val(data.telephone);

                        $recorder.val(data.recorder);
                        $recordTime.val(data.recordTime);
                        $remark.val(data.remarks);

                        if(data.imgList){
                            showEditImg(data.imgList);
                        }
                    }
                }
            });
        }

        var filter = {
            getSubmit: function () {
                var data = {};
                data.mode = true;
                //环境ID
                data.id = $ambientId;
                //名称参数
                data.name = function () {
                    var v = $name.val();
                    if (v) {
                        return v;
                    }else{
                        $name.TIP({content:'名称不能为空！'});
                        data.mode = false;
                    }
                }();
                //特定场所类别参数
                data.type = function () {
                    var v = $genre.val();
                    if (v) {
                        return v;
                    }else{
                        $('#JQ_resource_genre').TIP({content:'资源类别不能为空！'});
                        data.mode = false;
                    }
                }();
                //省$('#JQ_resource_capital')
                data.province = function () {
                    var v = $capital.val('text');
                    if (v) {
                        return v;
                    }else{
                        $('#JQ_resource_capital').TIP({content:'省份不能为空！'});
                        data.mode = false;
                    }
                }();
                //市
                data.city = function () {
                    var v = $city.val('text');
                    if(v){
                        return v;
                    }else{
                        $('#JQ_resource_city').TIP({content:'市不能为空！'});
                        data.mode = false;
                    }
                }();
                //区
                data.district = function () {
                    var v = $county.val('text');
                    if (v) {
                        return v;
                    }else{
                        $('#JQ_resource_county').TIP({content:'区县不能为空！'});
                        data.mode = false;
                    }
                }();
                //镇和乡
                data.town = function () {
                    var v = $town.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //村
                data.village = function () {
                    var v = $village.val();
                    if (v) {
                        return v;
                    }else{
                        $village.TIP({content:'街道/村不能为空！'});
                        data.mode = false;
                    }
                }();
                //联系人、单位参数
                data.contact = function () {
                    var v = $contact.val();
                    if (v) {
                        return v;
                    }else{
                        $contact.TIP({content:'联系人不能为空！'});
                        data.mode = false;
                    }
                }();
                //联系方式参数
                data.telephone = function () {
                    var v = $tel.val();
                    if (v) {
                        return v;
                    }else{
                        $tel.TIP({content:'联系方式不能为空！'});
                        data.mode = false;
                    }
                }();
                //记录人参数
                data.recorder = function () {
                    var v = $recorder.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //记录时间参数
                data.recordTime = function () {
                    var v = $recordTime.val();
                    if (v) {
                        if(!(Dyy.checkDateLate(v,curData))){
                            $recordTime.TIP({content:'记录时间不能大于当前时间'});
                            data.mode = false;
                        }
                        return v;
                    }
                    return "";
                }();
                //备注参数
                data.remarks = function () {
                    var v = $remark.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                // 照片
                data.imgs = function(){
                    var $label = $('span.zy-noninternal-span-img');
                    var arr = [];
                    if($label.length > 0){
                        $label.each(function(){
                            var $this_label = $(this);
                            arr.push($this_label.attr('data-id'));
                        });
                    }
                    return arr;
                }();
                return data;
            }
        };
        //保存
        $("#JQ_save").click(function(){
            var $form = $('#JQ_resource_create_form');
            var bool = $form.verify();
            var param = filter.getSubmit();
            if(param.mode){
                if(bool){
                    DyyBase.ajax(ambientApi.url_ae_emergency_save(), DyyBase.convertToArr(param), function(dataSet){
                        if(dataSet.bool){
                            if(dataSet.result >= 1){
                                $(this).MSG({
                                    type: 'success',
                                    height: 300,
                                    content: '保存成功',
                                    yesBtnTxt: '确认',
                                    yesBtnAct: function(){
                                        window.location.href = ambientApi.url_ae_emergency_success();
                                    }
                                });
                            }
                        }
                    });
                }
            }

        })
    }

    //难以维修接近
    function loadHard(){
        //输入框
        var $reason = $("#JQ_hard_reason").select3({search:false});  //难以维修接近
        DyyBase.ajax(ambientApi.url_common_form_type('AE_DIFFICULTY_REPAIR_TYPE'), {}, function(dataset){
            var json = DyyBase.getSelect(dataset);
            $reason.add(json);
        });


        var $number = $("#JQ_hard_number");  //编号

        var $beginNumber = $("#JQ_hard_begin_number");  //起点-桩号
        var $beginSpace = $("#JQ_hard_begin_space");  //起点-最近桩距离
        var $beginX = $("#JQ_hard_begin_x");  //起点-X
        var $beginY = $("#JQ_hard_begin_y");  //起点-Y
        var $beginZ = $("#JQ_hard_begin_z");  //起点-Z

        var $endNumber = $("#JQ_hard_end_number");  //终点-桩号
        var $endSpace = $("#JQ_hard_end_space");  //终点-最近桩距离
        var $endX = $("#JQ_hard_end_x");  //终点-X
        var $endY = $("#JQ_hard_end_y");  //终点-Y
        var $endZ = $("#JQ_hard_end_z");  //终点-Z

        var $position = $("#JQ_hard_position");  //位置描述

        if($ambientId){
            DyyBase.ajax(ambientApi.url_ae_difficulty_examine(), {id:$ambientId,type:'edit'}, function(dataSet){
                if(dataSet.bool){
                    var data = dataSet.result;
                    if(data){
                        $hard_pipeline.fit(data.pipeLineId);

                        $number.val(data.customNumber);

                        $beginNumber.val(data.beginNagmInput);
                        $beginSpace.val(data.beginNagmMileageInput);
                        $beginX.val(data.beginX);
                        $beginY.val(data.beginY);
                        $beginZ.val(data.beginZ);

                        $endNumber.val(data.endNagmInput);
                        $endSpace.val(data.endNagmMileageInput);
                        $endX.val(data.endX);
                        $endY.val(data.endY);
                        $endZ.val(data.endZ);

                        $position.val(data.locationDescription);
                        $reason.fit(data.reason);

                        $recorder.val(data.recorder);
                        $recordTime.val(data.recordTime);
                        $remark.val(data.remarks);

                        if(data.imgList){
                            showEditImg(data.imgList);
                        }
                    }
                }
            });
        }

        var filter = {
            getSubmit: function () {
                var data = {};
                data.mode = true;
                //环境ID
                data.id = $ambientId;
                //管道名称参数
                data.pipeLineId = function () {
                    var v = $hard_pipeline.val();
                    if(v){
                        return v;
                    }else{
                        $('#JQ_hard_pipeline').TIP({content:'管道名称不能为空！'});
                        data.mode = false;
                    }
                }();
                //编号参数
                data.customNumber = function () {
                    var v = $number.val();
                    if (v) {
                        return v;
                    }else{
                        $number.TIP({content:'编号不能为空！'});
                        data.mode = false;
                    }
                }();
                //起点-桩号参数
                data.beginNagmInput = function () {
                    var v = $beginNumber.val();
                    if (v) {
                        return v;
                    }else{
                        $beginNumber.TIP({content:'桩号不能为空！'});
                        data.mode = false;
                    }
                }();
                //起点-相对桩的距离参数
                data.beginNagmMileageInput = function () {
                    var v = $beginSpace.val();
                    if (v) {
                        return v;
                    }else{
                        $beginSpace.TIP({content:'相对桩的距离不能为空！'});
                        data.mode = false;
                    }
                }();
                //起点-X
                data.beginX = function () {
                    var v = $beginX.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //起点-Y
                data.beginY = function () {
                    var v = $beginY.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //起点-Z
                data.beginZ = function () {
                    var v = $beginZ.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //终点-桩号参数
                data.endNagmInput = function () {
                    var v = $endNumber.val();
                    if (v) {
                        return v;
                    }else{
                        $endNumber.TIP({content:'桩号不能为空！'});
                        data.mode = false;
                    }
                }();
                //终点-相对桩的距离参数
                data.endNagmMileageInput = function () {
                    var v = $endSpace.val();
                    if (v) {
                        return v;
                    }else{
                        $endSpace.TIP({content:'相对桩的距离不能为空！'});
                        data.mode = false;
                    }
                }();
                //终点-X
                data.endX = function () {
                    var v = $endX.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //终点-Y
                data.endY = function () {
                    var v = $endY.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //终点-Z
                data.endZ = function () {
                    var v = $endZ.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //位置描述
                data.locationDescription = function () {
                    var v = $position.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //难以接近原因
                data.reason = function () {
                    var v = $reason.val();
                    if (v) {
                        return v;
                    }else{
                        $("#JQ_hard_reason").TIP({content:'难以接近原因不能为空！'});
                        data.mode = false;
                    }
                }();
                //记录人参数
                data.recorder = function () {
                    var v = $recorder.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //记录时间参数
                data.recordTime = function () {
                    var v = $recordTime.val();
                    if (v) {
                        if(!(Dyy.checkDateLate(v,curData))){
                            $recordTime.TIP({content:'记录时间不能大于当前时间'});
                            data.mode = false;
                        }
                        return v;
                    }
                    return "";
                }();
                //备注参数
                data.remarks = function () {
                    var v = $remark.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                // 照片
                data.imgs = function(){
                    var $label = $('span.zy-noninternal-span-img');
                    var arr = [];
                    if($label.length > 0){
                        $label.each(function(){
                            var $this_label = $(this);
                            arr.push($this_label.attr('data-id'));
                        });
                    }
                    return arr;
                }();
                return data;
            }
        };

        //保存
        $("#JQ_save").click(function(){
            var $form = $('#JQ_hard_create_form');
            var bool = $form.verify();
            var param = filter.getSubmit();
            if(param.mode){
                if(bool){
                    DyyBase.ajax(ambientApi.url_ae_difficulty_save(), DyyBase.convertToArr(param), function(dataSet){
                        if(dataSet.bool){
                            if(dataSet.result >= 1) {
                                $(this).MSG({
                                    type: 'success',
                                    height: 300,
                                    content: '保存成功',
                                    yesBtnTxt: '确认',
                                    yesBtnAct: function () {
                                        window.location.href = ambientApi.url_ae_difficulty_success();
                                    }
                                });
                            }
                        }
                    });
                }
            }

        })
    }

    //管道占压接近
    function loadOccupy(){
        //输入框
        var $type = $("#JQ_occupy_type").select3({search:false});  //类型
        DyyBase.ajax(ambientApi.url_common_form_type('AE_PRESS_OBJECT_TYPE'), {}, function(dataset){
            var json = DyyBase.getSelect(dataset);
            $type.add(json);
        });
        var $findType = $("#JQ_occupy_findType").select3({search:false});  //发现方式
        DyyBase.ajax(ambientApi.url_common_form_type('AE_FOUND_WAY'), {}, function(dataset){
            var json = DyyBase.getSelect(dataset);
            $findType.add(json);
        });

        var $name = $("#JQ_occupy_name");  //名称
        var $contact = $("#JQ_occupy_contact");  //联系人
        var $tel = $("#JQ_occupy_tel");  //联系方式

        var $beginNumber = $("#JQ_occupy_begin_number");  //起点-桩号
        var $beginSpace = $("#JQ_occupy_begin_space");  //起点-最近桩距离
        var $beginX = $("#JQ_occupy_begin_x");  //起点-X
        var $beginY = $("#JQ_occupy_begin_y");  //起点-Y
        var $beginZ = $("#JQ_occupy_begin_z");  //起点-Z

        var $position = $("#JQ_occupy_position");  //位置描述
        var $space = $("#JQ_occupy_space");  //与管道最小间距
        var $deep = $("#JQ_occupy_deep");  //管道埋深
        var $findTime = $("#JQ_occupy_findTime");  //发现日期

        if($ambientId){
            DyyBase.ajax(ambientApi.url_ae_press_examine(), {id:$ambientId,type:'edit'}, function(dataSet){
                if(dataSet.bool){
                    var data = dataSet.result;
                    if(data){
                        $occupy_pipeline.fit(data.pipeLineId);
                        $type.fit(data.type);
                        $findType.fit(data.foundWay);


                        $name.val(data.name);
                        $contact.val(data.contact);
                        $tel.val(data.telephone);

                        $beginNumber.val(data.nagmInput);
                        $beginSpace.val(data.nagmMileageInput);
                        $beginX.val(data.positionX);
                        $beginY.val(data.positionY);
                        $beginZ.val(data.positionZ);

                        $position.val(data.locationDescription);
                        $space.val(data.minDistance);
                        $deep.val(data.coverDepth);
                        $findTime.val(data.foundDate.slice(0,10));

                        $recorder.val(data.recorder);
                        $recordTime.val(data.recordTime);
                        $remark.val(data.remarks);

                        if(data.imgList){
                            showEditImg(data.imgList);
                        }
                    }
                }
            });
        }

        var filter = {
            getSubmit: function () {
                var data = {};
                data.mode = true;
                //环境ID
                data.id = $ambientId;
                //管道名称参数
                data.pipeLineId = function () {
                    var v = $occupy_pipeline.val();
                    if(v){
                        return v;
                    }else{
                        $('#JQ_occupy_pipeline').TIP({content:'管道名称不能为空！'});
                        data.mode = false;
                    }
                }();
                //类型参数
                data.type = function () {
                    var v = $type.val();
                    if(v){
                        return v;
                    }else{
                        $('#JQ_occupy_type').TIP({content:'类型不能为空！'});
                        data.mode = false;
                    }
                }();
                //名称参数
                data.name = function () {
                    var v = $name.val();
                    if (v) {
                        return v;
                    }else{
                        $name.TIP({content:'编号不能为空！'});
                        data.mode = false;
                    }
                }();
                //联系人参数
                data.contact = function () {
                    var v = $contact.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //联系方式参数
                data.telephone = function () {
                    var v = $tel.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //起点-桩号参数
                data.nagmInput = function () {
                    var v = $beginNumber.val();
                    if (v) {
                        return v;
                    }else{
                        $beginNumber.TIP({content:'桩号不能为空！'});
                        data.mode = false;
                    }
                }();
                //起点-相对桩的距离参数
                data.nagmMileageInput = function () {
                    var v = $beginSpace.val();
                    if (v) {
                        return v;
                    }else{
                        $beginSpace.TIP({content:'相对桩的距离不能为空！'});
                        data.mode = false;
                    }
                }();
                //起点-X
                data.positionX = function () {
                    var v = $beginX.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //起点-Y
                data.positionY = function () {
                    var v = $beginY.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //起点-Z
                data.positionZ = function () {
                    var v = $beginZ.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //位置描述
                data.locationDescription = function () {
                    var v = $position.val();
                    if (v) {
                        return v;
                    }else{
                        $position.TIP({content:'特定场所类别不能为空！'});
                        data.mode = false;
                    }
                }();
                //与管道最小间距
                data.minDistance = function () {
                    var v = $space.val();
                    if (v) {
                        return v;
                    }
                }();
                //管道埋深
                data.coverDepth = function () {
                    var v = $deep.val();
                    if (v) {
                        return v;
                    }
                }();

                //发现日期
                data.foundDate = function () {
                    var v = $findTime.val();
                    if (v) {
                        if(!(Dyy.checkDateLate(v,curData))){
                            $findTime.TIP({content:'发现日期不能大于当前日期'});
                            data.mode = false;
                        }
                        return v;
                    }else{
                        $findTime.TIP({content:'发现日期不能为空！'});
                        data.mode = false;
                    }
                }();

                //发现方式参数
                data.foundWay = function () {
                    var v = $findType.val();
                    if(v){
                        return v;
                    }else{
                        $('#JQ_occupy_findType').TIP({content:'发现方式不能为空！'});
                        data.mode = false;
                    }
                }();

                //记录人参数
                data.recorder = function () {
                    var v = $recorder.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                //记录时间参数
                data.recordTime = function () {
                    var v = $recordTime.val();
                    if (v) {
                        if(!(Dyy.checkDateLate(v,curData))){
                            $recordTime.TIP({content:'记录时间不能大于当前时间'});
                            data.mode = false;
                        }
                        return v;
                    }
                    return "";
                }();
                //备注参数
                data.remarks = function () {
                    var v = $remark.val();
                    if (v) {
                        return v;
                    }
                    return "";
                }();
                // 照片
                data.imgs = function(){
                    var $label = $('span.zy-noninternal-span-img');
                    var arr = [];
                    if($label.length > 0){
                        $label.each(function(){
                            var $this_label = $(this);
                            arr.push($this_label.attr('data-id'));
                        });
                    }
                    return arr;
                }();
                return data;
            }
        };

        //保存
        $("#JQ_save").click(function(){
            var $form = $('#JQ_occupy_create_form');
            var bool = $form.verify();
            var param = filter.getSubmit();
            if(param.mode){
                if(bool){
                    DyyBase.ajax(ambientApi.url_ae_press_save(), DyyBase.convertToArr(param), function(dataSet){
                        if(dataSet.bool){
                            if(dataSet.result >= 1) {
                                $(this).MSG({
                                    type: 'success',
                                    height: 300,
                                    content: '保存成功',
                                    yesBtnTxt: '确认',
                                    yesBtnAct: function () {
                                        window.location.href = ambientApi.url_ae_press_success();
                                    }
                                });
                            }
                        }
                    });
                }
            }
        })
    }

    /*** 相对位置关系改变 start ***/
    function checkThirdPosition(tag,div1,div2){
        var v = tag.val();
        if(v == 'CROSS'){
            div1.show();
            div2.hide();
        }else if(v == 'PARALLEL'){
            div1.hide();
            div2.show();
        }else{
            div1.hide();
            div2.hide();
        }
    }
    /*** 相对位置关系改变 start ***/

})(jQuery, window, document);